﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.Server;

using nxMgr;

namespace nxMgr
{
    public partial class FormMain : Form
    {
        private TfsTeamProjectCollection m_tpc;
        private WorkItemStore m_wis;
        private string m_projname;
        private Project m_proj;


        public FormMain()
        {
            InitializeComponent();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void connectToTFSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TeamProjectPicker tp = new TeamProjectPicker();
            switch(tp.ShowDialog(this))
            {
                case System.Windows.Forms.DialogResult.OK:
                    m_tpc = tp.SelectedTeamProjectCollection;
                    foreach( ProjectInfo pi in tp.SelectedProjects){
                        m_projname = pi.Name;
                        break;
                    }
                    break;
            }
            
            //MessageBox.Show(m_proj);
            m_wis = m_tpc.GetService<WorkItemStore>();
            m_proj = m_wis.Projects[m_projname];
            buttonSearchWorkItems.Enabled = true;
            //m_wis = Convert.ChangeType(m_tpc.GetService(typeof(WorkItemStore)), typeof(WorkItemStore));
            //m_wis = (WorkItemStore)(m_tpc.GetService(GetType(WorkItemStore)));
        }

        private void buttonSearchWorkItems_Click(object sender, EventArgs e)
        {
            using (FormSearchForWorkItem f = new FormSearchForWorkItem(m_wis, m_proj.Name))
            {
                f.ShowDialog(this);
            }
        }
    }
}
